/**
 * 
 * @authors Tao (972990430@qq.com)
 * @date    2017-07-09 17:38:47
 * @version $Id$
 */
/*-------------------------------------------品牌月统计--------------------------------*/
backHomeApp.controller('brandStatisticsCtrl', ['$scope', "DPUtil", "brandStatisticsService", "$uibModal", "UIUtil", "brandManageService",
    function($scope, DPUtil, brandStatisticsService, $uibModal, UIUtil, brandManageService) {
        $scope.conditions = {};
        DPUtil.initPage($scope, $scope.conditions);
        $scope.getAllBrand = function() {
            brandManageService.allList().then(function(data) {
                $scope.brands = data;
            });
        }
        $scope.getAllBrand();
        $scope.chartData = [];
        $scope.conditions.type = "0";
        /**
         * [query 查询]
         */
        $scope.query = function(type) {
            $scope.conditions.intoStartDate = DPUtil.getDateToString($scope.conditions.start_date);
            $scope.conditions.intoEndDate = DPUtil.getDateToString($scope.conditions.end_date);
            if (type) {
                $scope.conditions.page = 1;
            };
            brandStatisticsService.list($scope.conditions).then(function(data) {
                $scope.data = data.content;
                $scope.total = data.recordCount;
                $scope.chartData = [];
                for (var i = 0; i < $scope.data.length; i++) {
                    var obj = {
                        value:$scope.data[i].count,
                        name:$scope.data[i].brandName
                    }
                    $scope.chartData.push(obj);
                }
            });
        };
        $scope.query();
        /**
         * [changePageSize 分页数量]
         */
        $scope.changePageSize = function() {
            $scope.conditions.rows = $scope.page_size.value;
            $scope.conditions.page = 1;
            $scope.query();
        };

        $scope.clearQuery = function() {
            DPUtil.cleanQuery($scope.conditions);
            $scope.conditions.type = "0";
        }
    }
]);
/*-------------------------------------------店面月统计--------------------------------*/
backHomeApp.controller('storeStatisticsCtrl', ['$scope', "DPUtil", "storeStatisticsService", "$uibModal", "UIUtil", "storeManageService",
    function($scope, DPUtil, storeStatisticsService, $uibModal, UIUtil, storeManageService) {
        $scope.conditions = {};
        DPUtil.initPage($scope, $scope.conditions);
        $scope.getAllBrand = function() {
            var obj = {
                page: 1,
                rows: 999999
            }
            storeManageService.list(obj).then(function(data) {
                $scope.stores = data.content;
            });
        }
        $scope.getAllBrand();
        $scope.conditions.type = "0";
        $scope.chartData = [];
        /**
         * [query 查询]
         */
        $scope.query = function(type) {
            $scope.conditions.intoStartDate = DPUtil.getDateToString($scope.conditions.start_date);
            $scope.conditions.intoEndDate = DPUtil.getDateToString($scope.conditions.end_date);
            if (type) {
                $scope.conditions.page = 1;
            };
            storeStatisticsService.list($scope.conditions).then(function(data) {
                $scope.data = data.content;
                $scope.total = data.recordCount;
                $scope.chartData = [];
                for (var i = 0; i < $scope.data.length; i++) {
                    var obj = {
                        value:$scope.data[i].count,
                        name:$scope.data[i].companyName
                    }
                    $scope.chartData.push(obj);
                }
            });
        };
        $scope.query();


        /**
         * [changePageSize 分页数量]
         */
        $scope.changePageSize = function() {
            $scope.conditions.rows = $scope.page_size.value;
            $scope.conditions.page = 1;
            $scope.query();
        };

        $scope.clearQuery = function() {
            DPUtil.cleanQuery($scope.conditions);
            $scope.conditions.type = "0";
        }
        $scope.detail = function(param){
            storeStatisticsService.detail(param).then(function(data){
                _fn.showDetail(data)
            });

        }
        var _fn = {
            showDetail: function(data) {
                $uibModal.open({
                    animation: true,
                    templateUrl: 'detail.html',
                    keyboard: false,
                    backdrop: 'static',
                    size: "lg",
                    controller: ["$scope", "$uibModalInstance",
                        function(detail_scope, uibModal) {
                            detail_scope.store_detail = data.content;
                            detail_scope.cancel = function() {
                                uibModal.close();
                            }
                        }
                    ]
                });
            }
        }
    }
]);
/*-------------------------------------------销售月统计--------------------------------*/
backHomeApp.controller('saleStatisticsCtrl', ['$scope', "DPUtil", "salesmanStatisticsService", "$uibModal", "UIUtil","storeManageService",
    function($scope, DPUtil, salesmanStatisticsService, $uibModal, UIUtil,storeManageService) {
        $scope.conditions = {};
        DPUtil.initPage($scope, $scope.conditions);
        $scope.getAllBrand = function() {
            var obj = {
                page: 1,
                rows: 999999
            }
            storeManageService.list(obj).then(function(data) {
                $scope.stores = data.content;
            });
        }
        $scope.getAllBrand();
        $scope.conditions.type = "0";
        $scope.chartData = [];
        /**
         * [query 查询]
         */
        $scope.query = function(type) {
             $scope.conditions.intoStartDate = DPUtil.getDateToString($scope.conditions.start_date);
            $scope.conditions.intoEndDate = DPUtil.getDateToString($scope.conditions.end_date);
            if (type) {
                $scope.conditions.page = 1;
            };
            salesmanStatisticsService.list($scope.conditions).then(function(data) {
                $scope.data = data.content;
                $scope.total = data.recordCount;
                $scope.chartData = [];
                for (var i = 0; i < $scope.data.length; i++) {
                    var obj = {
                        value:$scope.data[i].count,
                        name:$scope.data[i].sellName
                    }
                    $scope.chartData.push(obj);
                }
            });
        };
        $scope.query();


        /**
         * [changePageSize 分页数量]
         */
        $scope.changePageSize = function() {
            $scope.conditions.rows = $scope.page_size.value;
            $scope.conditions.page = 1;
            $scope.query();
        };

        $scope.clearQuery = function() {
            DPUtil.cleanQuery($scope.conditions);
            $scope.conditions.type = "0";
        }
    }
]);